#include "bullet.h"
#include "qgraphicsscene.h"



bullet::bullet(QGraphicsItem *parent)
{
    QPixmap test(":/gameresource/tile_0068.png");
    setPixmap(test);
    //setPixmap(QPixmap("qrc:/gameresource/tile_0068.png"));
    moveTimer = new QTimer(this);
    connect(moveTimer, &QTimer::timeout, this, &bullet::move);
    moveTimer->start(16);  // 每 16 毫秒移动一次（约 60FPS）

}

void bullet::setvelocity(qreal v)
{
    velocity=v;
}

void bullet::setx(qreal x)
{
    this->x=x;

}

void bullet::sety(qreal y)
{
    this->y=y;
}



void bullet::move()
{
    x=x+velocity*1.0/60;
    setPos(x,y);
    if(x>scene()->width()||x<0){
        scene()->removeItem(this);
        delete this;
    }

}
